<template>
    <ul>
        <li :style="{opacity}">欢迎学习</li>
        <li>news001 <input type="text"></li> 
        <li>news002 <input type="text"></li> 
        <li>news003 <input type="text"></li> 
    </ul>
</template>

<script>
import { getCurrentInstance, onBeforeUnmount, onMounted, ref } from 'vue'

export default {
    name:'News',
    data(){
       return {
        a:false,
        opacity:1
       }
    },
    // setup(){
    //     const instance = getCurrentInstance();
    //     const opacity = ref(1);
    //     onMounted(()=>{
    //         instance.timer = setInterval(()=>{
    //             console.log('@@@')
    //             opacity.value -= 0.01
    //             if(opacity.value <= 0) opacity.value = 1
    //         },16)
    //     })
    //     onBeforeUnmount(()=>{
    //         console.log("News组件被销毁了")
    //         clearInterval(instance.timer)
    //     })
    //     return {
    //         opacity
    //     }
    // },
    activated(){
        // console.log('News组件被激活了')
        this.timer = setInterval(()=>{
                console.log('@@@')
                this.opacity -= 0.01
                if(this.opacity <= 0) this.opacity = 1
            },16)
    },
    deactivated(){
        // console.log('News组件失活了')
        clearInterval(this.timer)

    }
}
</script>

<style>

</style>